﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BlogDH
{
    public partial class Content : System.Web.UI.Page
    {
        protected string BlogName = string.Empty;
        protected string BlogUrl = string.Empty;
        protected string BlogTags = string.Empty;
        protected string BlogDesc = string.Empty;
        protected string BlogCode = string.Empty;
        protected string BlogTime = string.Empty;
        protected string BlogArea = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["url"]))
            {
                ShowBlogInfo();
            }
        }

        private void ShowBlogInfo()
        {
            BlogUrl = HttpUtility.UrlDecode(Request.QueryString["url"]).Replace('_', '.');
            Model.BlogInfo blogInfo = new DAL.BlogInfo().GetModel(BlogUrl);
            string tmp = "未知";
            if (blogInfo != null)
            {
                BlogName = blogInfo.BlogName;
                BlogUrl = string.Format("{0}{1}", blogInfo.IsWWW == 1 ? "www." : string.Empty, blogInfo.BlogUrl);
                BlogTags = string.IsNullOrEmpty(blogInfo.BlogTags) ? tmp : blogInfo.BlogTags;
                BlogDesc = string.IsNullOrEmpty(blogInfo.BlogDesc) ? tmp : blogInfo.BlogDesc;
                BlogCode = string.IsNullOrEmpty(blogInfo.CodeType) ? tmp : blogInfo.CodeType;
                BlogTime = string.Format("{0}-{1}", blogInfo.CreateYear, blogInfo.CreateMouth);

                List<Model.Area> areas = CommValue.AreaList;
                Model.Area area = areas.FirstOrDefault(x => x.AreaID == blogInfo.Sheng);
                if (area != null && area.AreaID > 0)
                {
                    BlogArea = area.Name;
                }
                else
                {
                    BlogArea = tmp;
                }
            }
        }
    }
}